import Vue from 'vue'
import store from './store/index'
import App from './App.vue'
import ElementUI from 'element-ui'
import VueRouter from 'vue-router'
import routes from './routers'
import 'element-ui/lib/theme-chalk/index.css'
import 'element-ui/lib/theme-chalk/display.css'
import './assets/style.css'
import fHeader from './components/f-header'
import fFooter from './components/f-footer'
import i18n from './i18n/i18n'
import  VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import axios from 'axios'



Vue.use(VueQuillEditor)
Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.component("f-header",fHeader)
Vue.component("f-footer",fFooter)
Vue.prototype.$ajax = axios
//Vue.use(ElementUI, {
//i18n: (key, value) => i18n.t(key, value)
//})

const router =new VueRouter({
	routes,
	mode: 'history'
})

router.beforeEach((to,from,next)=>{
	if(to.path.startsWith('/login')){
		window.localStorage.removeItem('access-admin')
		next()
	}
	else{
		let admin=JSON.parse(window.localStorage.getItem('access-admin'))
		if(!admin){
			next({path:'/login'})
		}
		else{
			axios({
				url:'http://localhost:8080/system/yesapiBjyOauthUser/checktoken',
				method:'get',
				headers:{
					token:admin.accessToken
				}
			}).then((response)=>{
				if(!response.data){
					console.log('校验失败')
					next({path:'/error'})
				}
				else{
					window.localStorage.setItem('isviewnickname',true);
					console.log(window.localStorage.getItem('isviewnickname'))
				}
			})
			next()
		}
	}
})

new Vue({
	router,
	i18n,
	store,
	render: h => h(App),
}).$mount('#app')
